package com.boyicloud.exchangeserver.web.controller

import com.boyicloud.exchangeserver.common.*
import com.boyicloud.exchangeserver.domain.ClientInfo
import com.boyicloud.exchangeserver.web.sevice.ClientService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("client")
class ClientController {

    @Autowired
    lateinit var clientService: ClientService

    @RequestMapping("/equipment/list")
    fun listEquipment(): Result<List<ClientInfo>> {
        val lists: List<ClientInfo> = DataBase.equipmentListMap.values.toList()
        return Result(data = lists)
    }

    @RequestMapping("/software/list")
    fun listSoftware(): Result<List<ClientInfo>> {
        val lists: List<ClientInfo> = DataBase.softwareListMap.values.toList()
        return Result(data = lists)
    }

    @RequestMapping("/list")
    fun list(): Result<ListResp> {
        return Result(data = clientService.list())
    }

    @RequestMapping("/reset")
    fun reset(): Result<String> {
        clientService.reset()
        return Result(data = "下线成功")
    }

    @RequestMapping("/offline")
    fun offline(@RequestBody offlineParam: OfflineParam): Result<String> {
        clientService.offline(offlineParam.ids)
        return Result(data = "下线完成")
    }

    @RequestMapping("/exchange")
    fun exchange(@RequestBody exchangeParam: ExchangeParam): Result<String> {
        clientService.exchange(exchangeParam)
        return Result(data = "配置成功")
    }

    @RequestMapping("/disconnect")
    fun disconnect(id: Long): Result<String> {
        clientService.disconnect(id)
        return Result(data = "断开透传成功")
    }
}